package com.climber.android.commonsdk.util;

import android.view.View;

public class OnSingleClickListener implements View.OnClickListener {

    private View.OnClickListener origin;
    // 两次点击按钮之间的点击间隔不能少于600毫秒
    private long timems = 600;
    private static long lastClickTime;

    public OnSingleClickListener(View.OnClickListener origin, long timems) {
        this.origin = origin;
        this.timems = timems;
    }

    public OnSingleClickListener(View.OnClickListener origin) {
        this.origin = origin;
    }

    @Override
    public void onClick(View v) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= timems) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            origin.onClick(v);
        }
    }
}
